import { Component, Input, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';

import { LoveComponentsService } from '../love-components.service';

@Component({
  selector: 'app-user-info-modal',
  templateUrl: './user-info-modal.component.html',
  styleUrls: ['./user-info-modal.component.scss']
})
export class UserInfoModalComponent implements OnInit {
  @Input() userId: any;

  userInfoData: any = {};
  isVisible: boolean = false;
  isSpinning: boolean = false;

  constructor(
    private message: NzMessageService,
    private services: LoveComponentsService
  ) { }

  ngOnInit(): void {
  }

  async loadData() {
    try {
      let params = {
        id: this.userId
      }
      this.isSpinning = true;
      const res: any = await this.services.getUserInfo(params);
      this.isSpinning = false;
      
      if (res.code == 0) {
        const { list } = res.data || {};
        this.userInfoData = list[0] || {};
      } else {
        this.message.error(res.message);
      }
    } catch (error: any) {
      this.isSpinning = false;
      this.message.error(error);
    }
  }

  handleCancel(): void {
    this.userInfoData = {};
    this.isVisible = false;
  }
}
